package com.example.viewpageapplication.adapter;

import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.viewpageapplication.R;
import com.example.viewpageapplication.entity.BaseT;

import java.util.List;

public class RecycleVAdapter extends RecyclerView.Adapter {

    public List<BaseT> message = BaseT.getDefalutList();
    private Context context;

    public RecycleVAdapter(Context context, List<BaseT> message) {
        this.message = message;
        this.context = context;
    }

    class Recylehholderv extends RecyclerView.ViewHolder{
        TextView tv ,tv2;
        public Recylehholderv(@NonNull View itemView) {
            super(itemView);

            //实例化自定义对象
            tv = (TextView) itemView.findViewById(R.id.tv_1);
            tv2 = (TextView) itemView.findViewById(R.id.tv_2);
        }
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        Recylehholderv recylehholderv = new Recylehholderv(LayoutInflater.from(context).inflate(R.layout.recycle_item,parent,false));
        return recylehholderv;
    }

    //对控件进行赋值
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

        Recylehholderv recylehholderv = (Recylehholderv) holder;
        recylehholderv.tv.setText("item" + position);
        recylehholderv.tv2.setText(message.get(position).message);

        recylehholderv.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,message.get(position).message+"被点击了",Toast.LENGTH_SHORT).show();
            }
        });

    }

    @Override
    public int getItemCount() {
        return 3;
    }
}
